﻿using Architecture.Repository.Interface.Traceability;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Traceability.Domain.BreedDomain;

namespace Traceability.Domain.Service.BreedService
{
    /// <summary>
    /// 养殖服务
    /// </summary>
    public class BreedService : IBreedService
    {
        /// <summary>
        /// 养殖仓储
        /// </summary>
        protected readonly IBreedRepository breedRepository;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="breedRepository">养殖仓储</param>
        public BreedService(IBreedRepository breedRepository)
        {
            this.breedRepository = breedRepository;
        }

        /// <summary>
        /// 添加养殖信息
        /// </summary>
        /// <param name="breed">养殖实体</param>
        /// <returns>返回受影响的行数</returns>
        public async Task<int> AddBreed(Breed breed)
        {
            return await breedRepository.AddAsync(breed);
        }

        /// <summary>
        /// 获取养殖信息
        /// </summary>
        /// <returns>返回养殖信息列表</returns>
        public async Task<List<Breed>> GetBreedList(int shoppingId)
        {
            return await breedRepository.GetAsync(x=>x.ShoppingId==shoppingId && !x.IsDeleted);
        }

        /// <summary>
        /// 反填养殖信息
        /// </summary>
        /// <param name="breedId">养殖ID</param>
        /// <returns>返回养殖信息</returns>
        public async Task<Breed> GetBreedModel(int breedId)
        {
            return await breedRepository.GetModelAsync(breedId);
        }

        /// <summary>
        /// 修改养殖信息
        /// </summary>
        /// <param name="breed">养殖实体</param>
        /// <returns>返回受影响的行数</returns>
        public async Task<int> UpdateBreed(Breed breed)
        {
            return await breedRepository.UpdateAsync(breed);
        }
    }
}
